<?php

namespace App\Http\Controllers\admin;

use App\Model\System_basic;
use App\Model\System_code;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class SystemController extends Controller
{
    public function index()
    {
        $item = System_basic::orderBy('id','desc')->first();

        return view('admin.system.system-base',compact('item'));
    }

    public function store(Request $request)
    {
        if ($request->input('tab-1') == 1){
            if ($request->hasFile('logo')){
                $logoFile = $request->file('logo');
                $postfixArr = ['png','jpg','jpeg','gif'];
                if (!in_array($logoFile->getClientOriginalExtension(),$postfixArr)){
                    return $this->error('不支持的图片格式');
                }
                $logoPath = $logoFile->store('uploads'.'/'.date('Y-m-d'));
            }else{
                $logoPath = $request->input('logo') ? $request->input('logo') : '';
            }
            if ($request->hasFile('icon')){
                $iconFile = $request->file('icon');
                $postfixArr = ['png','jpg','jpeg','gif'];
                if (!in_array($iconFile->getClientOriginalExtension(),$postfixArr)){
                    return $this->error('不支持的图片格式');
                }
                $iconPath = $iconFile->store('uploads'.'/'.date('Y-m-d'));
            }else{
                $iconPath = $request->input('icon') ? $request->input('icon') : '';
            }
            $m = new System_basic();
            $m->title = $request->input('title');
            $m->keywords = $request->input('keywords');
            $m->description = $request->input('description');
            $m->copyright = $request->input('copyright');
            $m->record_number = $request->input('record_number');
            $m->address = $request->input('address');
            $m->mobile = $request->input('mobile');
            $m->email = $request->input('email');
            $m->qq = $request->input('qq');
            $m->tel = $request->input('tel');
            $m->logo = $logoPath;
            $m->icon = $iconPath;
            if ($m->save()){
                return $this->success('添加成功');
            }else{
                return $this->error('添加失败');
            }
        }elseif ($request->input('tab-2') == 2){
            dd($request->all());
        }else{
            $m = new System_code();
            $m->shangqiao = $request->input('baidu-shangqiao');
            $m->tongji = $request->input('baidu-tongji');
            $m->lixianbao = $request->input('li-xian-bao');
            if ($m->save()){
                return $this->success('添加成功');
            }else{
                return $this->error('添加失败');
            }
        }
    }
}
